package cn.edu.neusoft.yuejian_02.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import cn.edu.neusoft.yuejian_02.R;
import cn.edu.neusoft.yuejian_02.adapter.ActivityAdapter;
import cn.edu.neusoft.yuejian_02.bean.ActivityBean;
import cn.edu.neusoft.yuejian_02.listener.RetrofitListener;
import cn.edu.neusoft.yuejian_02.model.ActivityModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class ActivityListFragment extends Fragment implements RetrofitListener {

    private View view=null;
    private RecyclerView recyclerView;
    public ActivityListFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view= inflater.inflate(R.layout.fragment_activity_list2, container, false);
        initView();
        initData();
        return view;
    }

    private void initView() {
        recyclerView = (RecyclerView) view.findViewById(R.id.rcv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));

    }

    private void initData() {
        ActivityModel activityModel = new ActivityModel();

        activityModel.ActivityList(this);

    }

    @Override
    public void onSuccess(Object object) {
        List<ActivityBean> activityBean = (List<ActivityBean>) object;
        recyclerView.setAdapter(new ActivityAdapter(getActivity(),activityBean));
    }

    @Override
    public void onFail() {

    }
}
